package group5_Project3;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class PersonForm implements ActionListener {
	String firstname;
    String lastname;
    private String ssn;
    int age;
    static JFrame frame;
    static JPanel pPanel;
    static JPanel buttons;
    public static PersonForm p;
    public static void main(String[] args){
    	frame = new JFrame("Person");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container pane = frame.getContentPane();
        pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

        pPanel = new JPanel(new GridLayout(0,2));
        pPanel.add(new JLabel("First Name:"));
        final JTextField fName = new JTextField();
        pPanel.add(fName);
        pPanel.add(new JLabel("Last Name:"));
        final JTextField lName = new JTextField(); 
        pPanel.add(lName);
        pPanel.add(new JLabel("SSN:"));
        final JTextField ssn = new JTextField();
        pPanel.add(ssn);
        pPanel.add(new JLabel("Age:"));
        final JTextField age = new JTextField();
        pPanel.add(age);
        frame.add(pPanel);
        
       
        JButton submit = new JButton("Submit");
        submit.addActionListener(new ActionListener() {
                
        	@Override
    		public void actionPerformed(ActionEvent e) {
        		int age1 = Integer.parseInt(age.getText());	
    			p = new PersonForm(fName.getText(), lName.getText(), ssn.getText(), age1); 
        	}
        });
        pPanel.add(submit);
                
        JButton cancel = new JButton("Cancel");
        cancel.addActionListener(new PersonForm());
        pPanel.add(cancel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
         }
    
        public PersonForm(){
        }
        public PersonForm(String firstname, String lastname, String ssn, int age){
        	this.firstname = firstname;
        	this.lastname = lastname;
        	this.setSsn(ssn);
        	this.age = age;
        	System.out.println(this);
        	System.out.println("person constructor");
        }

		public String getSsn() 
    	{
    		return ssn;
    	}
    	
    	public void setSsn(String ssn) 
    	{
    		this.ssn = ssn;
    	} 

        @Override
    	public String toString()
    	{
    		return "First Name: " + this.firstname + "\nLastName: " + this.lastname + 
    				"\nAge: " + this.age + "\nSSN: " + this.getSsn();
    		   	}
        @Override
        public void actionPerformed(ActionEvent e) {
        	System.exit(0);
        }
       
}
